﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using NUnit.Framework;
using Rhino.Mocks;

using Chefbook.UserActions;
using Chefbook.ViewModels;
using System.Globalization;

namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class CreateIngredientActionFixture
    {
        private IUserAction action;
        private CategoryViewModel category;
        private RecipeViewModel recipe;

        [SetUp]
        public void Init()
        {
            category = new CategoryViewModel(new Category(null)) { Name = "root" };
            recipe = new RecipeViewModel(new Recipe(category.CategoryModel));
            Assert.AreEqual(0, recipe.Ingredients.Count);

            action = new CreateIngredientAction(recipe);
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.AreEqual(1, recipe.Ingredients.Count);
            Assert.Contains(recipe, category.Recipes);
            var newIngredient = recipe.Ingredients.First();
            Assert.Contains(newIngredient, recipe.Ingredients);
        }

        [Test]
        public void UndoActionTest()
        {
            action.DoAction();
            action.UndoAction();
            Assert.AreEqual(0, recipe.Ingredients.Count);
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void UndoActionTwiceAfterDoingTest()
        {
            UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }

        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format(CultureInfo.CurrentUICulture, "Create ingredient in Recipe '{0}'", recipe), action.ToString());
        }
    }
}
